import {url} from '../../util/config'
import login from "../login";
import {message} from "antd";
import $ from 'jquery'

function getNewLogin(searchKey=null,type=null,personNum=null,subStatus=null,startDate=null,endDate=null,current=null,pageSize=null) {
    return managerSubLogList(searchKey,type,personNum,subStatus,startDate,endDate,current,pageSize)
}

export default function managerSubLogList(searchKey=null,type=null,personNum=null,subStatus=null,startDate=null,endDate=null,current=null,pageSize=null) {

    let token = localStorage.getItem("token")

    let status = {
        count:null,
        data:null
    };
    debugger
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`subscribe/list?searchKey=${searchKey}&type=${type}&personNum=${personNum}&status=${subStatus}&startDate=${startDate}&endDate=${endDate}&current=${current}&pageSize=${pageSize}`,
        type: 'get',
        success: function (result) {
            if(result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(searchKey,type,personNum,subStatus,startDate,endDate,current,pageSize)
            }else {
                status.data = result.result
                status.count = result.count
            }
        },
        error:function (error) {
            status.data = "error"
            message.error("请求异常");
        }
    })
    return status
}
